package com.zaimokuza.cn.controller;

import com.zaimokuza.cn.entity.ChartData;
import com.zaimokuza.cn.entity.response.ResponseFormat;
import com.zaimokuza.cn.entity.statistics.ManageStatisticsData;
import com.zaimokuza.cn.entity.statistics.UserStatisticsData;
import com.zaimokuza.cn.service.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;

/**
 * @author zaimokuza
 */
@Api(tags = "统计相关")
@ResponseFormat
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Resource
    private StatisticsService statisticsService;

    @ApiOperation(value = "查询用户相关统计信息", notes = "查询用户相关统计信息")
    @GetMapping("/user")
    public ArrayList<UserStatisticsData> getUserStatisticsData(@RequestParam(defaultValue = "7") Integer interval) {
        return statisticsService.getUserStatisticsData(interval);
    }

    @ApiOperation(value = "查询网站相关统计信息", notes = "查询网站相关统计信息")
    @GetMapping("/manage")
    public ManageStatisticsData getManageStatisticsData() {
        return statisticsService.getManageStatisticsData(LocalDate.now().minusDays(1).toString());
    }

    @ApiOperation(value = "查询网站登录率集合", notes = "查询网站登录率集合")
    @GetMapping("/manage/loginRate")
    public ArrayList<ChartData> getLoginRateList(@RequestParam(defaultValue = "7") Integer interval) {
        return statisticsService.getLoginRateList(LocalDate.now().minusDays(1).toString(), interval);
    }

}
